<?php 
function list_pendidikan($penilaian_id,$karyawan_id){
	$karyawans= loaddata_karyawan($karyawan_id);
	$header  = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:50ps'), 
		'Evaluasi'=>array('style'=>'border-bottom:2px solid;width:200px'),  
		'Uraian Hasil Kerja'=>array('style'=>'border-bottom:2px solid;width:200px'),  
		'Nilai'=>array('style'=>'text-align:center;border-bottom:2px solid;width:60px'),   
	);
	$status=( isset($karyawans['kelompok_evaluasi']) ? $karyawans['kelompok_evaluasi'] : 'Pelaksana' ) ;
	$query = "SELECT * FROM evaluasi  a
			INNER JOIN unsur_evaluasi b ON a.unsur_evaluasi_id = b.unsur_evaluasi_id
			WHERE b.penilaian_id={$penilaian_id} 
			AND b.".$status."='Y' 
			ORDER BY a.unsur_evaluasi_id,a.evaluasi_id ";
	
	$result = my_query($query);
	$i = 0;
	$total_nilai=0;
	$unsur_evaluasi_id=0;
	$row = array();
	while($r = my_fetch_array($result) ){
		$i++;
		if($unsur_evaluasi_id<>$r['unsur_evaluasi_id']){
			$unsur_evaluasi_id=$r['unsur_evaluasi_id'];
			$row[] = array(
				'#'=> ' ',      
				'evaluasi'=> wordwrap( $r['nama_unsur_evaluasi'],35, "<br>\n") ,
				'uraian'=> ' ',
				'nilai'=>' ' ,  
			); 		
		}


		$skor = get_skor_value($karyawan_id , $r['evaluasi_id']);		
		$fskor = array(
			'name'=>'fskor',
			'id'=>'fskor_'.$r['evaluasi_id'],
			'value'=>(int)$skor,
			'size'=>'3',
		);
		$skor_form = form_dynamic($fskor);
		$row[] = array(
			'#'=> $i,      
			'evaluasi'=> wordwrap( $r['nama_evaluasi'], 35, "<br>\n") ,
			'uraian'=> wordwrap($r['uraian'], 55, "<br>\n").'<br><br>' ,
			'nilai'=> $skor   ,  
		); 
		$total_nilai+=$skor;
	}
	$rata_rata=ROUND($total_nilai/$i,0);
	$nilais=get_evaluasi_nilai($rata_rata);	
	$row[] = array(
		'#'=> ' ',      
		'evaluasi'=> 'RATA-RATA NILAI : '.$rata_rata.' / '.$nilais['huruf'].' / '.$nilais['keterangan'],
		'uraian'=>   'T O T A L'  , 
		'nilai'=> $total_nilai, 
	); 	 
	$datas = table_cetak_rows($row); 

	$property_table = array(
		'style'=>'border-collapse:collapse;margin:2px;',
		'cellpadding'=>'2',
		'cellspacing'=>'0'
	);	
	
	$view = '<table cellspacing="4px" class="content_view" ';
	foreach($property_table as $table=>$property){
		$view .= $table.'="'.$property.'" ';
	}
	$penilaians = my_get_data_by_id('penilaian','penilaian_id',$penilaian_id );
	$view .='>'."\n";
	$view .= '<tr><td style="width:30%">Periode</td><td style="width:70%">'. date( "m-Y" , strtotime($penilaians['tanggal'])).'</td></tr>';
	$view .= '<tr><td style="width:30%">Nama</td><td style="width:70%">'.$karyawans['nama_gelar'].'</td></tr>';
	$view .= '<tr><td style="width:30%">NIK</td><td style="width:70%">'.$karyawans['nik'].'</td></tr>';
	$view .='</table><br><br>';
	return $view. table_cetak_builder($header , $datas ,  4 , false );
} 


function get_skor_value($karyawan_id , $evaluasi_id){
	$evaluasi_id=( isset($evaluasi_id) ? $evaluasi_id : 0 ) ;
	$query = "SELECT nilai FROM penilaian_karyawan_evaluasi 
		WHERE karyawan_id ={$karyawan_id} AND
		evaluasi_id ={$evaluasi_id}
	"; 
	$result = my_query($query);
	if(my_num_rows($result) > 0){
		$row = my_fetch_array($result);
		return $row['nilai']; 
	}return false;
}

function get_evaluasi_nilai($angka){
	$nilai=$angka+1;
	$query = "SELECT * FROM evaluasi_nilai 
		WHERE angka<".$nilai." ORDER BY angka desc LIMIT 1
	"; 
	//var_dump($query);
	$result = my_query($query);
	if(my_num_rows($result) > 0){
		$row = my_fetch_array($result);
		return $row; 
	}
	return false;
}
?>

<style type="text/css">
<!--
.aaa{color:red}
	table.page_header {width: 100%; border: none; background-color: #CDCDCD; border-bottom: solid 1mm #000; padding: 2mm }
	table.page_footer {width: 100%; border: none;  border-top: solid 1mm #000; padding: 2mm}
div.zone
{
	border: solid 2mm #66AACC;
	border-radius: 3mm;
	padding: 1mm;
	background-color: #FFEEEE;
	color: #440000;
}
div.zone_over
{
	width: 30mm;
	height: 35mm;
	overflow: hidden;
}

-->
</style>
<page style="font-size: 10pt">
	<page_footer>
		<table class="page_footer">
			<tr>
				<td style="width: 33%; text-align: left;">
					 HRIS RSKM 
				</td>
				<td style="width: 34%; text-align: center">
					page [[page_cu]]/[[page_nb]]
				</td>
				<td style="width: 33%; text-align: right">
					M A P &copy; 2010 - <?php echo date('Y'); ?>
				</td>
			</tr>
		</table>
	</page_footer>
	<?php if($i ==0){ ?>
	<div style="width: 100%; text-align:center; padding:2px; font-size: 13pt ;">Data Penilaian Karyawan </div>
	<?php } ?>
	<?php echo list_pendidikan($_GET['penilaian_id'],$_GET['karyawan_id']) ?> 
</page>